#include "../../mqserver/connect.hpp"
#include <gtest/gtest.h>

MyRabbitMQ::ConnectionManager::ptr connections;

class ConnectionTest : public testing::Environment
{
    virtual void SetUp() override
    {
        connections = std::make_shared<MyRabbitMQ::ConnectionManager>();
    }

    virtual void TearDown() override
    {

    }

};

//增加连接测试
TEST(ConnectionTest,create_test)
{
    connections->createConnection(muduo::net::TcpConnectionPtr(),MyRabbitMQ::ProtobufCodecPtr(),
    threadpool::ptr(),
    std::make_shared<MyRabbitMQ::VirtualHost>("host-1","./data.db","./basedata"),
    MyRabbitMQ::ConsumerManager::ptr());

    connections->createConnection(muduo::net::TcpConnectionPtr(),MyRabbitMQ::ProtobufCodecPtr(),
    threadpool::ptr(),
    std::make_shared<MyRabbitMQ::VirtualHost>("host-2","./data.db","./basedata"),
    MyRabbitMQ::ConsumerManager::ptr());
}

//删除连接测试
TEST(ConnectionTest,delete_test)
{
    connections->removeConnection(muduo::net::TcpConnectionPtr());
}

//获取连接测试
TEST(ConnectionTest,get_test)
{
    ASSERT_EQ(connections->getConnection(muduo::net::TcpConnectionPtr()),MyRabbitMQ::Connection::ptr());
}

int main(int argc, char* argv[])
{
    
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ConnectionTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}